$(function () {
    const form = layui.form
    loadUserInfo()

    function loadUserInfo() {
        $.get('/my/userinfo', ).then(res => {
            form.val('form-info', res.data)
        })
    }
    $('#reset-btn').on('click', function (e) {
        e.preventDefault()
        loadUserInfo()
    })

    $('.layui-form').on('submit', function () {
        const data  = form.val('form-info')
        $.post('/my/userinfo', data).then(res => {
            if (res.status !== 0) {
                return layui.layer.msg(res.message || '修改失败')
            }
            layui.layer.msg(res.message)
        })
        return false
    })
})